package com.play.springflux.route;

import com.play.springflux.handler.UserHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.*;

@Component
public class AllRouter {

    @Bean
    RouterFunction<ServerResponse> userRouter(UserHandler userHandler) {
        return RouterFunctions.nest(RequestPredicates.path("/fun/user"),
                RouterFunctions.route(RequestPredicates.GET("/"), userHandler::getAllUser)
                        .andRoute(RequestPredicates.POST("/"), userHandler::createUser)
                        .andRoute(RequestPredicates.DELETE("/{id}"), userHandler::deleteUser)
        );
    }
}
